﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using XCI.Core;
using XCI.Sys.Model;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    /// <summary>
    /// 系统锁定用户管理
    /// </summary>
    [FormCaption("系统锁定用户管理")]
    public partial class FrmLockUserManager : BaseForm
    {
        private readonly bool allowDelete = SysApp.Permit("sys.lockUser.remove");

        public FrmLockUserManager()
        {
            InitializeComponent();
            gridControl.ModelType = typeof(SysLockUser);
        }

        /// <summary>
        /// 页面加载事件
        /// </summary>
        private async void FrmLockUserManager_Load(object sender, EventArgs e)
        {
            await gridControl.LoadAsync();
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        private async void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            await gridControl.DeleteAsync();
        }

        private async void btnSearch_Click(object sender, EventArgs e)
        {
            await gridControl.LoadAsync();
            gridView.ApplyFindFilter(editKey.Text.Trim());
        }

        private void GridControl_LoadData(object sender, LoadDataEventArgs e)
        {
            e.Task = async () => new PagingList<SysLockUser>(await SysAccountService.Instance.GetLockUserListAsync(null));
        }

        private async void GridControl_DeleteData(object sender, DeleteDataEventArgs e)
        {
            await SysAccountService.Instance.RemoveLockUserAsync(gridControl.SelectedId);
        }

        private void GridControl_RowSelectionChanged(object sender, EventArgs e)
        {
            btnDelete.Enabled = gridControl.HasSelected && allowDelete;
        }
    }
}